<html>
<head><meta charset="utf-8"><title>backtrace crate: printing · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html">backtrace crate: printing</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="151445923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151445923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151445923">(Dec 11 2018 at 13:39)</a>:</h4>
<p><span class="user-mention" data-user-id="116015">@Alex Crichton</span> is there any deep reason why the pretty-printing of <a href="https://docs.rs/backtrace/0.3.9/backtrace/struct.Backtrace.html" target="_blank" title="https://docs.rs/backtrace/0.3.9/backtrace/struct.Backtrace.html">backtraces</a> is an <code>impl Debug</code>, not an <code>impl Display</code>? If you hand't told me, I'd never even have looked at this ins earch for pretty-printing.</p>



<a name="151446192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151446192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151446192">(Dec 11 2018 at 13:44)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> oh that's in theory a conventions thing where <code>Display</code> is intended for lossless formatting whereas <code>Debug</code> is "programmer output in any way possible". I didn't put a lot of effort in making it entirely lossless, but tbh that should probably be <code>Display</code> as well as <code>Debug</code> for that type</p>



<a name="151446247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151446247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151446247">(Dec 11 2018 at 13:45)</a>:</h4>
<p>I always thought <code>Debug</code> was meant to be lossless, as in "can ideally be parsed back by the compiler"?</p>



<a name="151446261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151446261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151446261">(Dec 11 2018 at 13:45)</a>:</h4>
<p>whereas <code>Display</code> is "pretty"</p>



<a name="151446328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151446328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151446328">(Dec 11 2018 at 13:46)</a>:</h4>
<p>At least for libstd it's different</p>



<a name="151446340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151446340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151446340">(Dec 11 2018 at 13:46)</a>:</h4>
<p>where <code>Debug</code> doesn't really mean anything, but <code>Display</code> is lossless (and parseable if possible) and pretty-ish</p>



<a name="151446682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151446682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151446682">(Dec 11 2018 at 13:52)</a>:</h4>
<p>that doesn't apply to <code>String</code>, for example. <code>Debug</code> is what you can parse (it escapes quotes and things), <code>Display</code> is just the raw string and not very suited for parsing</p>



<a name="151446798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151446798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151446798">(Dec 11 2018 at 13:55)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> for strings the <code>Display</code> is what you parse (it's just the raw bytes) whereas <code>Debug</code> is intended to show you any escapes and other tricky chars, if present</p>



<a name="151446906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151446906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151446906">(Dec 11 2018 at 13:57)</a>:</h4>
<p>hm. to me this quite clearly sounds like <code>Debug</code> is "more lossless"...</p>



<a name="151447200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151447200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151447200">(Dec 11 2018 at 14:01)</a>:</h4>
<p>String::from(Display::fmt(&amp;String)) is I believe guaranteed to produce the same string whereas that's (obviously) not true for the debug impl</p>



<a name="151447343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151447343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151447343">(Dec 11 2018 at 14:04)</a>:</h4>
<p>sure, but the debug output I can copy-paste into a <code>.rs</code> file and it'll parse the right way</p>



<a name="151447351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151447351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151447351">(Dec 11 2018 at 14:04)</a>:</h4>
<p>and that's also true for the derived <code>Debug</code> for enums and structs, and the one for tuples</p>



<a name="151447408"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151447408" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151447408">(Dec 11 2018 at 14:05)</a>:</h4>
<p>that's why I thought of it more lossless. I don't know any example where <code>Debug</code> shows <em>less</em> information that <code>Display</code>, which is what I would take as a witness for <code>Display</code> being the more lossless trait</p>



<a name="151447433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/backtrace%20crate%3A%20printing/near/151447433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/backtrace.20crate.3A.20printing.html#151447433">(Dec 11 2018 at 14:05)</a>:</h4>
<p>(this obviously doesn't matter very much, I am just curious how we arrived at seemingly contradictory mental models for these traits^^)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>